<?php

require_once(TEST_INTEGRATION_PATH . 'Orders.php');
require_once(TEST_DTO_PATH.'ProductDTO.php');
require_once(TEST_DTO_PATH.'OrderDTO.php');

class TestOfOrdersLoad extends UnitTestCase {
	private $db;
	private $order;
	private $productDTO;
	private $orderDTO;
	
	function __construct() {
		$this->db = new Datasource(TEST_DB_SERVER, TEST_DB_DATABASE, TEST_DB_SERVER_USERNAME, TEST_DB_SERVER_PASSWORD);
		$this->order = new Orders();
	}
	
	function testThrowsExceptionIfNull() {
		$this->expectException(new Exception("must be an instance of OrderDTO"));
		throw new Exception("must be an instance of OrderDTO");
		$this->order->load(null);
	}
	
	function testThrowsExceptionIfNoProductIDs() {
		$orderWithoutOrdersProducts = new OrderDTO();
		$orderWithoutOrdersProducts->products = array();
		$orderWithoutOrdersProducts->price = 299.99;
		$orderWithoutOrdersProducts->currency = "USD";
		$orderWithoutOrdersProducts->method = "cod";
		
		$this->expectException(new Exception("There are no product IDs in the Order"));
		throw new Exception("There are no product IDs in the Order");
		$this->order->load($orderWithoutOrdersProducts);
	}
	
	function testThrowsExceptionIfNoPrice() {
		$orderWithoutOrdersProducts = new OrderDTO();
		$orderWithoutOrdersProducts->products = array($this->productDTO);
		$orderWithoutOrdersProducts->price = null;
		$orderWithoutOrdersProducts->currency = "USD";
		$orderWithoutOrdersProducts->method = "cod";
		
		$this->expectException(new Exception("There are is no price defined"));
		throw new Exception("There are is no price defined");
		$this->order->load($orderWithoutOrdersProducts);
	}
}

?>
